import ir.DataNode;
import ir.LocatorServicePair;
import ir.SoapRootNode;
import ir.StubNode;

import java.util.List;
import java.util.Set;


/**
 * Walker that traverses the pseudo-AST built by Java Reflection.
 * During the walk, we will construct an Intermediate Representation
 * of the SOAP Stubs, Data Objects, Methods, and Fields for later processing.
 * 
 * 
 * 
 * @author tchau@google.com (Thomas Chau)
 *
 */
public class StubTreeWalker {

  
    private SoapRootNode rootNode;
  
//    public StubTreeWalker(Class<Object>[] stubs) {
    public StubTreeWalker(List<LocatorServicePair> pairs) {
      
      rootNode = new SoapRootNode();
      
//      for (Class<Object> stub : stubs) {
      for (LocatorServicePair p : pairs) {
        
        Class<Object> stub = p.getStub();
        Class<Object> locator = p.getLocator();
        String serviceName = p.getServiceName();
        
        // add stub node
        StubNode stubNode = new StubNode(stub, locator, serviceName);
        rootNode.addStubNode(stubNode);
        
        // required data types (SiteData, AdData, etc.)
        Set<DataNode> requiredDataNodes = stubNode.getRequiredDataNodes();
        
        /** TODO: what about types required by Data classes but not stubs? **/
        for (DataNode d : requiredDataNodes) {
          rootNode.addDataNode(d);
        }
      }
    }
    
    public SoapRootNode getRootNode() {
      return rootNode;
    }
}
